Release 10.1A: OpenEdge Getting Started:
Object-oriented Programming


Calling methods from inside a class

You can directly access methods from within the class where they are defined by invoking the method name. This includes all methods implemented directly within the class definition and all PUBLIC and PROTECTED methods implemented in any super class of the class hierarchy. Invoking an overridden method executes the method defined in the bottom-most subclass of any class hierarchy in which the invoking class is a part.

This is the syntax to invoke a method from inside a class:

Syntax
[ return-variable = ] method-name ( [ parameter [ , parameter ] ... ] ) 

Element descriptions for this syntax diagram follow:

return-variable

The name of the variable to hold any return value.

method-name

The name of an accessible method in the class hierarchy.

[ parameter [ , parameter ] ... ]

The parameters of the method. For more information on the syntax of parameter, see the “Parameter passing syntax” reference entry in OpenEdge Development: Progress 4GL Reference .

The compiler verifies that the parameters used in the method invocation are consistent with parameters defined for the method. The compiler verifies that the number, mode and data type of these parameters match exactly. There is no implicit conversion of any data types when passing method parameters. However, Progress does allow a dynamic temp-table or ProDataSet to be passed to static temp-table or ProDataSet parameter (respectively), and similarly for passing a static temp-table or ProDataSet to a corresponding dynamic temp-table or ProDataSet parameter.

Note: If the parameter is a class or interface type, the parameter is passed by value as an object reference. The effect of passing an object reference parameter is identical to assigning one object reference to another. For more information, see the "Defining an object reference as a parameter" section.

The following is an example from two of the sample classes, where acme.myObjs.Common.CommonObj is a super class of the class acme.myObjs.CustObj:

CLASS acme.myObjs.Common.CommonObj: 
    DEFINE PUBLIC VARIABLE timestamp AS DATETIME NO-UNDO. 
    METHOD PUBLIC VOID updateTimestamp( ): 
        timestamp = NOW. 
    END METHOD. 
    METHOD PROTECTED CLASS acme.myObjs.Common.ErrorObj ErrorHandler  
                                        (INPUT iObjType AS CHARACTER): 
        DEFINE VARIABLE rError AS CLASS acme.myObjs.Common.ErrorObj NO-UNDO. 
        rError = NEW acme.myObjs.Common.ErrorObj (INPUT iObjType). 
        RETURN rError. 
    END METHOD. 
END CLASS. 

The constructor in acme.myObjs.CustObj invokes the PROTECTED method ErrorHandler( ) within its class hierarchy by directly calling the method by its name:

CLASS acme.myObjs.CustObj INHERITS acme.myObjs.Common.CommonObj  
                          IMPLEMENTS acme.myObjs.Interfaces.IBusObj: 
    ... 
    DEFINE PRIVATE VARIABLE rError  
        AS CLASS acme.myObjs.Common.ErrorObj NO-UNDO. 
    CONSTRUCTOR PUBLIC CustObj( ): 
        ... 
        rError = ErrorHandler("acme.MyObjs.CustObj"). 
    END CONSTRUCTOR. 
    ... 
END CLASS. 

Comparison with procedure-based programming

Methods do not require a separately specified prototype in the class where they are invoked, as user-defined functions do in the procedure where they are invoked.


Copyright © 2005 Progress Software Corporation
www.progress.com
Voice: (781) 280-4000
Fax: (781) 280-4095